home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / amos / AMOS0398.lzh / AMOSLIST / 000328_amos-request@svcs1.digex.net_Tue Mar 31 00:05:13 1998.msg < prev    next >
Text File  |  1998-04-01  |  5KB  |  147 lines

  1. >From amos-request@svcs1.digex.net  Tue Mar 31 00:05:13 1998
  2. Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
  3.     by pony-1.mail.digex.net (8.8.8/8.8.8) with ESMTP id AAA09943
  4.     for <mcox@access.digex.net>; Tue, 31 Mar 1998 00:05:13 -0500 (EDT)
  5. Received: (from daemon@localhost)
  6.     by svcs1.digex.net (8.8.5/8.8.5) id TAA16621
  7.     for amos-out; Mon, 30 Mar 1998 19:14:54 -0500 (EST)
  8. Received: from pony-2.mail.digex.net (pony-2.mail.digex.net [204.91.241.6])
  9.     by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id TAA16618
  10.     for <amos-list@svcs1.digex.net>; Mon, 30 Mar 1998 19:14:53 -0500 (EST)
  11. Received: from mmi-mailrelay.ModusMedia.com (firefox.modusmedia.com [208.14.214.2])
  12.     by pony-2.mail.digex.net (8.8.8/8.8.8) with ESMTP id TAA22498
  13.     for <amos-list@access.digex.net>; Mon, 30 Mar 1998 19:14:52 -0500 (EST)
  14. From: Declan_Gorman@modusmedia.com
  15. Received: from smtp2.modusmedia.com ([192.168.131.84])
  16.           by mmi-mailrelay.ModusMedia.com (Post.Office MTA v3.1
  17.           release PO205e ID# 0-0U10L2S100) with SMTP id AAA157
  18.           for <amos-list@access.digex.net>; Mon, 30 Mar 1998 16:46:03 -0700
  19. Received: from ccMail by smtp2.modusmedia.com
  20.   (IMA Internet Exchange 3.0 Enterprise) id 0000E383; Mon, 30 Mar 98 16:39:45 -0700
  21. Mime-Version: 1.0
  22. Date: Mon, 30 Mar 1998 09:21:57 -0700
  23. Message-ID: <0000E383.eval@modusmedia.com>
  24. Subject: Re[2]: Sorting Problem
  25. To: Rune Zedeler <rzedeler@post10.tele.dk>
  26. Cc: AMOS List <amos-list@access.digex.net>
  27. Content-Type: text/plain; charset=US-ASCII
  28. Content-Transfer-Encoding: 7bit
  29. Content-Description: cc:Mail note part
  30. Status: O
  31. X-Status: 
  32.  
  33.      
  34.      Thanks, I will try this out later.  One thing I should point out is 
  35.      that I made a bit of an error when I said 128 blocks of 256k.  This 
  36.      should read 128 of 256 bytes.  Would this have much effect on the code 
  37.      provided below?
  38.  
  39.  
  40. ______________________________ Reply Separator _________________________________
  41. Subject: Re: Sorting Problem
  42. Author:  Rune Zedeler <rzedeler@post10.tele.dk> at Internet
  43. Date:    27/03/98 20:50
  44.  
  45.  
  46. On 16-Mar-98, Declan_Gorman@modusmedia.com wrote:
  47.      
  48. >     My program has a memory bank which consists of 128 blocks of memory, 
  49. >     each 256k in size.  Each memory block has a name and category and I 
  50. >     want to be able to sort the bank by either.
  51.      
  52. This should do it:
  53.      
  54. <CUT>
  55.      
  56. ' Needs sorting string to be located in S_STR$(0) to S_STR$(NUM-1) 
  57. '   ( ... I don't know how to pass arrays to procs...) 
  58.      
  59. _SORT[128,256*1024,BANK_NUMBER,NUMBER_OF_ITEMS_IN_ARRAY,UNUSED_BANK]
  60.      
  61. Procedure _SORT[NUM,SIZ,BNK,ARR_SIZ,TMP_BNK]
  62.   Shared S_STR$()
  63.      
  64.   Reserve As Work TMP_BNK,SIZ
  65.   Dim CUR(NUM-1),OLD(NUM-1)
  66.      
  67.   'Add number of item to the end of the string 
  68.   For I=0 To NUM-1 : S_STR$(I)=S_STR$(I)+Hex$(I,4) : Next I
  69.   'ensure that unused items in array will be placed first after sorting 
  70.   If ARR_SIZ>NUM
  71.     For I=NUM To ARR_SIZ-1 : S_STR$(I)='' : Next I
  72.   End If 
  73.   Sort S_STR$(0)
  74.   'move sorted items FROM last TO first in array 
  75.   For I=0 To NUM-1 : S_STR$(I)=S_STR$(I+ARR_SIZ-NUM) : Next I
  76.      
  77.   'At this point the first NUM indexes in S_STR$() contains sorted 
  78.   'data - followed by the original position in the array.
  79.      
  80.   For I=0 To NUM-1 : CUR(I)=I : OLD(I)=I : Next I 
  81.   'CUR(ORIGINAL_POS) contains CURRENT_POS  
  82.   'OLD(CURRENT_POS) contains ORIGINAL_POS
  83.      
  84.   For I=0 To NUM-1
  85.     'OLDI=what index index I had before sorting. 
  86.     OLDI=Val(Right$(S_STR$(I),5))
  87.     'J=Current position of block 
  88.     J=CUR(OLDI)
  89.     Print OLDI,J
  90.     S_STR$(I)=Left$(S_STR$(I),Len(S_STR$(I))-5) 
  91.     'swap blocks:
  92.     If I<>J
  93.       Copy Start(BNK)+I*SIZ,Start(BNK)+(I+1)*SIZ To Start(TMP_BNK) 
  94.       Copy Start(BNK)+J*SIZ,Start(BNK)+(J+1)*SIZ To Start(BNK)+I*SIZ 
  95.       Copy Start(TMP_BNK),Start(TMP_BNK)+SIZ To Start(BNK)+J*SIZ 
  96.       Swap CUR(OLD(I)),CUR(OLD(J))
  97.       Swap OLD(I),OLD(J)
  98.     End If 
  99.   Next I
  100.   Erase TMP_BNK
  101. End Proc
  102.      
  103. <CUT>
  104.      
  105. Quick tech explanation (hmmm, how it works, eh):
  106. I use the internal AMOS sort cmd. But before sorting I add the hex number to 
  107. the end of the strings. So if the strings are:
  108.      
  109. Hi
  110. There
  111. !!!
  112.      
  113. then I add like this:
  114.      
  115. Hi$0000
  116. There$0001
  117. !!!$0002
  118.      
  119. After sorting (using "Sort") it is:
  120.      
  121. !!!$0002
  122. Hi$0000
  123. There$0001
  124.      
  125. - and I can use the numbers to move around in the bank.
  126.      
  127. I reserve a temp bank on the size of one block (that is 256k)
  128.      
  129. As I do not have 32MB of ram I have not been able to test it with your amount 
  130. of memory. It moves the memory three times. That is: It will move 96MB of 
  131. data! So it'll probably use a small amount of time.
  132.      
  133. Just write a letter to the list (send a copy to me personally, as I am only 
  134. very seldom at home and therefore incidentally skips some letters in the 
  135. mailinglists) if you have questions.
  136.      
  137. -- 
  138.      
  139.          /?\ __    __ /?????\           _         Rune Zedeler
  140. ________/ /// \\__/ \\\  ---/           \?-_      Peter Rordams Vej 19 
  141. \      / //?|  \\/  ||?\ \\??????????????   ?-_   2800 Lyngby
  142.  )    / //  | \ ` / ||  \ \\ Lemmus of Efreet  -  Denmark
  143. /    / ?????\\|\-'/ /????? \\____________   _-?
  144. ?????\------'/||??| \------'/           /_-?      rzedeler@post10.tele.dk
  145.       ??????\-'/  \-'/??????            ?         Tel: +45-45871730
  146.              ??    ??
  147.